import Vue from 'vue'
import VueRouter from 'vue-router'

// 注册页面
// import Reg from '@/views/Reg/Reg.vue'
// 登录页面
// import Login from '@/views/Login/Login.vue'
// 主页
// import Main from '@/views/Menus/Main.vue'
// 主页内容
// import Home from '@/views/Menus/Home/Home.vue'
// 个人信息页
// import UserInfo from '../views/Menus/User/UserInfo.vue'
// 修改头像
// import UserAvatar from '@/views/Menus/User/UserAvatar.vue'
// 修改密码页面
// import UserPwd from '@/views/Menus/User/UserPwd.vue'
// 文章分类页面
// import ArtCate from '@/views/Menus/article/ArtCate.vue'
// 发布文章
// import ArtList from '@/views/Menus/article/ArtList.vue'

// import store from '@/store'

Vue.use(VueRouter)

// 防止路由重复点击时，报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    name: 'Login',
    path: '/login',
    component: () => import('@/views/Login/Login.vue')
  },
  {
    name: 'Reg',
    path: '/reg',
    component: () => import('@/views/Reg/Reg.vue')
  },
  {
    name: 'Main',
    path: '/',
    component: () => import('@/views/Menus/Main.vue'),
    redirect: '/home',
    children: [
      {
        path: '/home',
        component: () => import('@/views/Menus/Home/Home.vue')
      },
      {
        name: 'UserInfo',
        path: 'user-info',
        component: () => import('../views/Menus/User/UserInfo.vue')
      },
      {
        name: 'UserPwd',
        path: 'user-pwd',
        component: () => import('@/views/Menus/User/UserPwd.vue')
      },
      {
        name: 'UserAvatar',
        path: 'user-avatar',
        component: () => import('@/views/Menus/User/UserAvatar.vue')
      },
      {
        name: 'ArtCate',
        path: 'art-cate',
        component: () => import('@/views/Menus/article/ArtCate.vue')
      },
      {
        name: 'ArtList',
        path: 'art-list',
        component: () => import('@/views/Menus/article/ArtList.vue')
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

// 路由的全局前置导航守卫：路由切换之前进行拦截
// router.beforeEach((to, from, next) => {
//   //  当用户访问  / 路径时，并且当前未登录，就要强行跳转到登录页
//   if (to.path === '/' && !store.state.token) {
//     Vue.prototype.$message.error('未登录！')
//     return next('/login')
//   }
//   next()
// })

export default router
